home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c++,comp.lang.c,comp.os.ms-windows.programmer.misc
- Subject: Re: fastest code
- Date: 12 Apr 1996 11:19:19 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4km6r7INNst8@keats.ugrad.cs.ubc.ca>
- References: <316112A2.7D37@public.sta.net.cn> <4kgu7g$n9a@solutions.solon.com> <4kjc9n$f7j@samba.rahul.net> <316E1037.41C67EA6@scn.de>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <316E1037.41C67EA6@scn.de>,
- Gerolf Wendland <wendland%hpp015%hpp001.mch2.scn.de@scn.de> wrote:
- >Whoever started this, he wrote:
- >>
- >> >>: >> for (i=0; i<16; i++)
- >> >>: >> prom[i] = prom[i+i];
- >> >
- >> >>: HUH? the code as written has a clear effect, which is to shove all of
- >> >>: the elements of an array over one. It certainly is an optimizer bug.
- > ^^^^^^^^^^^^^^
- >Really?
- >
- >Richard Krehbiel:
- >>In fact, I wrote exactly this loop once whose purpose was to initialize the
- >>parity bits in memory, but be non-destructive in case it was just a
- >>restart and not a power-on.
- >
- >This seems to indicate that prom[i] are assigned a values that are never used.
- >Maybe the optimizer has seen this. It should have issued a warning, which (the
- >issueing) may have been prevented by not prom being the variable but by the
- >somewhat anonymous locations prom[i] being the variables in question. The optimizer
- >would have been even better if it had seen the fact that the loop is superflouos
- >and had removed it as well.
- >
- >The volatile keyword is surely a good way to circumvent this problem.
-
- It may be and it may not be. Using keywords isn't going to fix a bug in the
- compiler, though it may work around it.
-
- As I stated earlier, I looked into the actual device driver, and the values
- _are_ used. Also a complete example program was shown here which prints the
- values of the array, as an example of clear afterward use. It failed to compile
- properly. The printing loop produced the original values, not the transformed
- array you expect.
-
- The volatile keyword should have no effect on this with a correctly functioning
- compiler. Suppose that the assignments to prom[] were optimized away into
- a register file, or some internal cache on the CPU (this is not too far
- fetched---a DSP compiler might quite well do this). A subsequent use of the
- array would still show the correct answer, regardless of the underlying code
- sequence.
-
- The keyword should not change the value produced by a program when used in
- conjunction of a variable that is not truly volatile. prom[] is not a memory
- mapped hardware port, it's not a global variable accessed by signal handlers,
- and the function in which it is used does not use setjmp/longjmp.
- --
-
-